package mango.server;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import java.io.*;

public class Gateway extends Thread {

    public BufferedReader in = null;
    public ServerSocket listenSocket;
    public ThreadGroup threadGroup;
	public java.awt.List connectionList;
	public Vector connections;
	public Vulture vulture;
	public MangoServer parent;
    
    public Gateway (ServerSocket listener, ThreadGroup tg, Vulture v, java.awt.List c, Vector con, MangoServer m) {
        super("Gateway");
        listenSocket = listener;
        vulture = v;
        connectionList = c;
        parent = m;
        connections = con;
        
        this.start();
    }
    
    public void run() {
		try {
			while (true) {
				Socket clientSocket = listenSocket.accept();
				Connection c = new Connection(clientSocket, threadGroup, 3, vulture, parent);
				
				synchronized (connections) {
					connections.addElement(c);
					connectionList.addItem(c.toString());					
				}
				
			}
		}
		catch (IOException e) {
			System.err.println("<!> Error listening for connections: "+e);
			System.exit(-1);
		}
	}

}
